package com.cloudlead.common.worker.web;

import com.cloudlead.common.lang.ObjectStatus;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * worker的基本信息
 */
public class WorkerInfo implements Serializable {

    private static final long serialVersionUID = -2813120366138988480L;
    public static final String DEFAULT_WORKER_IP = "127.0.0.1";
    public static final int DEFAULT_WORKER_PORT = 9090;

    private ObjectStatus status;

    private String workerName;

    private String workerIp;

    private int workerPort;

    private Map<String, List<String>> actions;

    private Map<String, Set<String>> modules;

    public WorkerInfo() {
        this(DEFAULT_WORKER_IP, DEFAULT_WORKER_PORT);
    }

    public WorkerInfo(int workerPort) {
        this(DEFAULT_WORKER_IP, workerPort);
    }

    public WorkerInfo(String workerIp, int workerPort) {
        this.workerIp = workerIp;
        this.workerPort = workerPort;
        status = ObjectStatus.enabled;
    }


    public ObjectStatus getStatus() {
        return status;
    }

    public void setStatus(ObjectStatus status) {
        this.status = status;
    }

    public String getWorkerName() {
        return workerName;
    }

    public void setWorkerName(String workerName) {
        this.workerName = workerName;
    }

    public int getWorkerPort() {
        return workerPort;
    }

    public String getWorkerIp() {
        return workerIp;
    }

    public void setWorkerIp(String workerIp) {
        this.workerIp = workerIp;
    }

    public void setWorkerPort(int workerPort) {
        this.workerPort = workerPort;
    }

    public Map<String, List<String>> getActions() {
        return actions;
    }

    public void setActions(Map<String, List<String>> actions) {
        this.actions = actions;
    }

    public Map<String, Set<String>> getModules() {
        return modules;
    }

    public void setModules(Map<String, Set<String>> modules) {
        this.modules = modules;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        WorkerInfo that = (WorkerInfo) o;

        if (workerPort != that.workerPort) return false;
        if (!workerName.equals(that.workerName)) return false;
        return workerIp.equals(that.workerIp);

    }

    @Override
    public int hashCode() {
        int result = workerName.hashCode();
        result = 31 * result + workerPort;
        result = 31 * result + workerIp.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "WorkerInfo{" +
                "workerName='" + workerName + '\'' +
                ", workerPort=" + workerPort +
                ", workerIp='" + workerIp + '\'' +
                '}';
    }
}

